#!/bin/bash

LOCP=$LOCKDIR

function lock() {

    if test -z "$CUSTOMER"; then CUSTOMER="tm"; fi
    if test -z "$HOSTNAME"; then HOSTNAME="tm"; fi
    if test -z "$JOBNAME"; then JOBNAME="tm"; fi

    if test -z "$1"
    then
        LOCF="$CUSTOMER-$HOSTNAME-$JOBNAME.lock"
    else
        LOCF="$CUSTOMER-$HOSTNAME-$JOBNAME.$1.lock"
    fi

    LOCK="$LOCP/$LOCF"

	if [ ! -d "$LOCP" ];  then mkdir -p $LOCP; fi

	if [ -f "$LOCK"  ]; 
	then 
		return 1
	else
		touch $LOCK
		return 0
	fi
}


function unlock() {

    if test -z "$CUSTOMER"; then CUSTOMER="tm"; fi
    if test -z "$HOSTNAME"; then HOSTNAME="tm"; fi
    if test -z "$JOBNAME"; then JOBNAME="tm"; fi

    if test -z "$1"
    then
        LOCF="$CUSTOMER-$HOSTNAME-$JOBNAME.lock"
    else
        LOCF="$CUSTOMER-$HOSTNAME-$JOBNAME.$1.lock"
    fi

    LOCK="$LOCP/$LOCF"

    if [ -f "$LOCK"  ];
    then
	    rm $LOCK
        return 0
    else
        return 1
    fi
}

# eof
